package com.ekuaitu.kuaitustaff.utils;

import android.text.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by csh on 2018/2/10.
 */
public class CheckRegexUtils {
    public static boolean checkPhoneNum(String str) {
        /*String regexp = "^1[3|4|5|7|8]\\d{9}$";
        Pattern pattern = Pattern.compile(regexp);
        Matcher matcher = pattern.matcher(str);*/
        return str.length() == 11;
    }

    public static boolean checkPassword(String str) {
        String regexp = "^[a-zA-Z0-9]{6,16}$";
        Pattern pattern = Pattern.compile(regexp);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }

    public static boolean checkIdCard(String str) {
        String regexp = "(^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}$)\n";
        Pattern pattern = Pattern.compile(regexp);
        Matcher matcher = pattern.matcher(str);
        return (matcher.matches());
    }

    public static boolean checkQRCode(String str) {
        String regexp = "([0-9]+)";
        Pattern pattern = Pattern.compile(regexp);
        Matcher matcher = pattern.matcher(str);
        return (matcher.matches());
    }

    /**
     * 判断是否是车牌号
     */
    public static boolean isCarNum(String CarNum) {
        //String carnumRegex = "^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Za-z]{1}[A-Za-z]{1}[警京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼]{0,1}[A-Z0-9a-z]{4}[A-Za-z0-9挂学警港澳]{1}$";
        if (TextUtils.isEmpty(CarNum)) return false;
        else return true;

    }

    /**
     * 验证用户名只包含字母，数字，中文
     *
     * @return@
     */
    public static String carNumFilter(String str) {
        String regEx = "[^a-zA-Z0-9\u4E00-\u9FA5]+$";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.replaceAll("").trim();

    }

    public static boolean checkParkName(String str) {
        str = str.trim();
        if (!TextUtils.isEmpty(str) && str.length() > 1) {
            int count = 0;
            Pattern pattern = Pattern.compile("\\p{P}");
            char c[] = str.toCharArray();
            for (int i = 0; i < c.length; i++) {
                Matcher matcher = pattern.matcher(String.valueOf(c[i]));
                if (matcher.matches()) {
                    count++;
                }
            }
            if (count < c.length) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}